package com.bestom.videoplay.util;

import android.os.Environment;
import android.util.Log;

import java.io.BufferedReader;
import java.io.File;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.LinkedList;


public class GetVideoFileUtil {



    public LinkedList<String> getFileList(String path) {
        LinkedList<String> videoList = new LinkedList<>();
        File file = new File(path);
        File[] files = file.listFiles();
        if (files != null) {
            for (File value : files) {
                String name = value.getName();
                if (value.isFile() && name.endsWith(".mp4")) videoList.add(path + name);
            }
        }
        return videoList;
    }

    public LinkedList<String> getFileList(String titleVideoPath, ArrayList<String> contentsVideoPaths) {

        LinkedList<String> videoList = new LinkedList<>();

        LinkedList<String> titleFileList = getFileList(titleVideoPath);

        for (int i = 0; i < titleFileList.size(); i++) {
            if (i != 3) videoList.add(titleFileList.get(i));
            videoList.addAll(getFileList(contentsVideoPaths.get(i)));
        }

        return videoList;
    }

    public LinkedList<String> getFileList(int index, String firstTitleVideoPath, String secondTitleVideoPath, ArrayList<String> contentsVideoPaths) {

        LinkedList<String> videoList = new LinkedList<>();

        videoList.add(firstTitleVideoPath + "C0" + index + ".mp4");

        LinkedList<String> titleFileList = getFileList(secondTitleVideoPath);

        for (int i = 0; i < titleFileList.size(); i++) {
            if (i != 3) videoList.add(titleFileList.get(i));
            String contentsVideoPath = contentsVideoPaths.get(i);
            videoList.add(contentsVideoPath + "C0" + index + "_" + contentsVideoPath.split("0")[1] + ".mp4");
        }
        return videoList;
    }

    public LinkedList<String> getFileList(int index, String firstTitleVideoPath, String secondTitleVideoPath, String contentsVideoPath) {

        LinkedList<String> videoList = new LinkedList<>();
        int firstIndex;
        index = index - 41;
        /*switch (index){
            case index < 8:
                firstIndex = 1;
                break;

        }*/
//        if (index)
        videoList.add(firstTitleVideoPath + "C0" + index + ".mp4");
        switch (index) {
            case 1:
                videoList.add(secondTitleVideoPath + "1_song.mp4");
                break;
            case 2:
                videoList.add(secondTitleVideoPath + "21_dolch.mp4");
                break;
            case 3:
                videoList.add(secondTitleVideoPath + "3_pw.mp4");
                break;
            case 4:
                videoList.add(contentsVideoPath + "C0" + index + "_" + index + ".mp4");
                break;
            case 5:
                videoList.add(secondTitleVideoPath + "5_phonics.mp4");
                break;
            case 6:
                videoList.add(secondTitleVideoPath + "6_story.mp4");
                break;
            case 7:
                videoList.add(secondTitleVideoPath + "7_game.mp4");
                break;
            default:
                break;
        }


        return videoList;
    }


    public boolean sdCardExist() {
        return Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED);
    }
}
